/*
 * File: shape.c
 * ---------------
 * This program draws simple shapes.
 */

#include "extgraph.h"
#include "genlib.h"

/* Function prototypes */

void DrawBox(double x, double y, double width, double height);
void DrawCenteredBox(double x, double y, double width, double height);
void DrawCenteredCircle(double x, double y, double r);
void DrawCenteredEllipse(double x, double y, double rx, double ry);

/* Main program */

int main(int argc, string args[]) {
    // 1. Initialize the graphics windows
    InitGraphics();
    // 2. Draw shapes in the background context
    MovePen(GetWindowWidth() / 2, 0);
    DrawLine(0, GetWindowHeight());
    MovePen(480, 100);
    DrawArc(50, 0, 360);
    MovePen(120, 350);
    DrawArc(50, 90, 180);
    DrawBox(400, 300, 100, 100);
    double cx = GetWindowWidth() / 2;
    double cy = GetWindowHeight() / 2;
    DrawCenteredBox(cx, cy, 200, 100);
    DrawCenteredCircle(cx, cy, 50);
    MovePen(600, 240);
    DrawEllipticalArc(50, 100, 0, 360);
    DrawCenteredEllipse(cx, cy, 100, 50);
    // 3. Update of the graphics window and wait for quit
    UpdateDisplay();
    WaitQuit();
}

/*
 * Function: DrawBox
 * Usage: DrawBox(x, y, width, height)
 * -----------------------------------
 * This function draws a rectangle of the given width and
 * height with its lower left corner at (x, y).
 */

void DrawBox(double x, double y, double width, double height) {
    MovePen(x, y);
    DrawLine(0, height);
    DrawLine(width, 0);
    DrawLine(0, -height);
    DrawLine(-width, 0);
}

/*
 * Function: DrawCenteredBox
 * Usage: DrawCenteredBox(x, y, width, height)
 * -------------------------------------------
 * This function draws a rectangle of the given width and
 * height with its center at (x, y).
 */

void DrawCenteredBox(double x, double y, double width, double height) {
    DrawBox(x - width / 2, y - height / 2, width, height);
}

/*
 * Function: DrawCenteredCircle
 * Usage: DrawCenteredCircle(x, y, r);
 * -----------------------------------
 * This function draws a circle of radius r with its
 * center at (x, y).
 */

void DrawCenteredCircle(double x, double y, double r) {
    MovePen(x + r, y);
    DrawArc(r, 0, 360);
}

/*
 * Function: DrawCenteredEllipse
 * Usage: DrawCenteredEllipse(x, y, rx, ry);
 * -----------------------------------
 * This function draws a ellipse of radius rx and ry with its
 * center at (x, y).
 */

void DrawCenteredEllipse(double x, double y, double rx, double ry) {
    MovePen(x + rx, y);
    DrawEllipticalArc(rx, ry, 0, 360);
}